/*
 * Universidad del Valle de Guatemala
 * Algoritmos y Estructura de Datos
 * Sergio Molina 10256
 * Hoja 9
 * 
*/


import java.util.*;

public class Graph<E>{ 

    private HashMap<E,LinkedList<Vertex<E>>> adjacencyMap; 
   /** 
    *  Initialize this Graph object to be empty. 
    */ 
    public Graph() { 
        adjacencyMap = new HashMap<E,LinkedList<Vertex<E>>>(); 
    } 
    
    
    /** 
     *  Determines if this Graph contains no Vertexs. 
     * 
     *  @return true - if this Graph contains no Vertexs. 
     */ 
    public boolean isEmpty() { 
            return adjacencyMap.isEmpty(); 
    } 
     
    
   /** 
     *  Determines the number of Vertexs in this Graph.  
     * 
     *  @return the number of Vertexs. 
     */ 
    
    
    public int size() { 
            return adjacencyMap.size(); 
    }
    
    public HashMap<E,LinkedList<Vertex<E>>> getMap(){
    	
    	return adjacencyMap;
    }
    
    public LinkedList<Vertex<E>> obtener(Object key){
    	return adjacencyMap.get(key);
    
    }
    
   /** 
   *  Adds a specified object as a vertex 
   * 
   *  @param vertex - the specified object     
   *  @return true - if object was added by this call              
   */ 
    public boolean addVertex (Vertex<E> vertex) {      
            if (adjacencyMap.containsKey(vertex.getValue())) 
                    return false; 
            adjacencyMap.put (vertex.getValue(), new LinkedList<Vertex<E>>()); 
            return true; 
    }  
    
   /** 
    *  Adds an edge, and Vertexs if not already present  
  * 
    *  @param v1 - the beginning vertex object of the edge  
    *  @param v2 - the ending vertex object of the edge 
    *  @return true - if the edge  was added by this call 
    */ 
    public boolean addEdge (E v1, E v2, int dist) { 
            	
    	Vertex<E> vert1=new Vertex<E>(v1,0);
    	Vertex<E> vert2=new Vertex<E>(v2,0);
    	Vertex<E> vert3=new Vertex<E>(v2,dist);
    	
    	addVertex (vert1); 
        addVertex (vert2); 
        LinkedList<Vertex<E>> l = adjacencyMap.get(vert1.getValue()); 
        l.add(vert3); 
        return true; 
    }  
}
